package com.autonavi.yunda.yunji.core.model.condition;

import com.autonavi.yunda.yunji.core.model.dto.HealthCheckLogDTO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import org.apache.logging.log4j.util.Strings;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author sunzhenbang
 */
@Data
public class HealthCheckLogQueryCondition {
    @NotBlank
    public String projectId;
    @NotNull
    public Integer pageNo;
    @NotNull
    public Integer pageSize;

    public String interfaceId;

    public List<Long> interfaceIdList;


    public QueryWrapper<HealthCheckLogDTO> fetchQueryWrapper() {
        QueryWrapper<HealthCheckLogDTO> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        if (!CollectionUtils.isEmpty(this.interfaceIdList)) {
            wrapper.in("interface_id", this.interfaceIdList);
        }
        if (Strings.isNotBlank(this.interfaceId)) {
            wrapper.eq("interface_id", this.interfaceId);
        }
        return wrapper;
    }
}

